#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 10;
ll a[N], prefix[35][N];

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int w = 0; w <= 30; w++) {
        for (int i = 1; i <= n; i++) {
            prefix[w][i] = prefix[w][i - 1] + (a[i] >> w & 1);
        }
    }
    while (m--) {
        ll l, r; cin >> l >> r;
        ll ans = 0;
        for (int w = 0; w <= 30; w++) {
            ans += (1 << w) * (prefix[w][r] - prefix[w][l - 1] ? 1 : 0);
        }
        cout << ans << endl;
    }
    return 0;
}